@import 'common';
@import 'mixins/button';
@import 'mixins/picker';

// Calendar Picker
// ----------------------

// Calendar Picker Name Space
@clpns: ~'@{ns}@{calendar-picker-prefix}';

.@{clpns} {
  background-color: @picker-bg;
  padding-top: @calendar-picker-padding;
  position: relative;
  min-height: 266px;
  overflow: hidden;
}

.@{clpns}-header {
  width: @calendar-header-width;
  padding-left: @calendar-picker-padding;
  padding-right: @calendar-picker-padding;
  .clearfix;

  // Month toolbar && Time toolbar
  &-month-toolbar,
  &-time-toolbar {
    display: inline-block;
  }

  &-month-toolbar {
    float: left;
  }

  &-time-toolbar {
    float: right;
  }

  // Month toolbar title && button
  &-title,
  &-backward,
  &-forward {
    .btn(base);
    .btn-subtle;
    .btn-xs(base);

    font-size: @font-size-base;
    line-height: @line-height-base;
  }

  &-title {
    margin: 0 @calendar-header-title-margin;
  }

  &-error {
    .btn-subtle-variant(@calendar-header-title-error-color);

    color: @calendar-header-title-error-color;
  }

  &-btn-disabled {
    &,
    &:hover,
    &:hover:focus {
      cursor: not-allowed;
      opacity: 0.3;
      background: none;
    }

    &::after {
      display: none !important;
    }
  }

  &-backward,
  &-forward {
    font-size: 0;
    width: @padding-extra-small-vertical * 2 + @font-size-small * @line-height-small;

    &::before {
      font-family: @font-family-icon;
      font-style: normal;
      font-size: @font-size-base;
    }
  }

  &-backward::before {
    content: @drop-left-caret-content;
  }

  &-forward::before {
    content: @drop-right-caret-content;
  }

  // Only Has month
  &-has-month:not(&-has-time) {
    margin: 0 auto;
    padding-left: @calendar-picker-padding;
    padding-right: @calendar-picker-padding;
  }

  &-has-month:not(&-has-time) &-month-toolbar {
    display: block;
    text-align: center;
    width: 100%;
    .clearfix;
  }

  &-has-month:not(&-has-time) &-backward {
    float: left;
  }

  &-has-month:not(&-has-time) &-forward {
    float: right;
  }

  // Only Has time
  &-has-time:not(&-has-month) {
    margin: 0 auto;
    text-align: center;
  }

  &-has-time:not(&-has-month) &-time-toolbar {
    float: none;
    display: inline-block;
  }

  // Has month && time
  &-has-month&-has-time {
    margin: 0 auto;
  }
}

.@{clpns}-view {
  padding: @calendar-picker-view-padding-top @calendar-picker-padding @calendar-picker-padding;
}

// Calendar Table
.@{clpns}-table {
  display: table;
}

.@{clpns}-table-row {
  display: table-row;
}

.@{clpns}-table-cell {
  display: table-cell;
  width: 1%;
  padding: @calendar-table-cell-padding;
  text-align: center;
  vertical-align: middle;

  &-un-same-month &-content,
  &-disabled &-content {
    &,
    &:hover {
      color: @calendar-table-cell-content-disabled-color;
    }
  }

  &-disabled &-content {
    &,
    &:hover {
      background: none;
      text-decoration: line-through;
      cursor: not-allowed;
    }
  }

  &-disabled&-is-today&-selected &-content {
    &:hover {
      .picker-calendar-cell-content-selected;
    }
  }

  &-disabled&-is-today &-content,
  &-disabled&-selected &-content {
    opacity: 0.3;
  }
}

.@{clpns}-table-cell-content {
  .picker-calendar-cell-content;

  .@{clpns}-table-cell-is-today & {
    border: @calendar-table-cell-content-today-border-width solid @calendar-table-cell-content-today-border-color;
    padding: @calendar-table-cell-content-padding - @calendar-table-cell-content-today-border-width;
  }

  .@{clpns}-table-cell-selected & {
    .picker-calendar-cell-content-selected;
  }
}

// Table header row
.@{clpns}-table-header-row {
  .@{clpns}-table-cell-content {
    color: @calendar-table-cell-header-color;
    font-size: @font-size-small;
    line-height: @line-height-small;
    padding-top: 2px;
    padding-bottom: 2px;

    &,
    &:hover,
    &:focus,
    &:hover:focus {
      background: none;
      cursor: auto;
    }
  }
}

// Calendar month dropdown
.@{clpns}-month-dropdown {
  display: none;
  position: absolute;
  top: @calendar-dropdown-top;
  border-top: 1px solid @B200;
  margin-top: 4px;
  width: 100%;
  background-color: @B000;
  overflow: hidden;
  z-index: @zindex-date-range-picker-table-cell-content;

  .@{clpns}-show-month-dropdown & {
    display: block;
  }

  .@{clpns}-show-month-dropdown &-content {
    animation: 0.3s linear slideDown;
  }

  &-scroll {
    height: 230px;
  }

  &-row {
    position: relative;
    padding-left: 40px + @calendar-picker-padding;
    padding-right: @calendar-picker-padding;
    padding-top: 5px;
    padding-bottom: 5px;

    &:not(:last-child) {
      border-bottom: 1px dotted @calendar-month-dropdown-row-border-color;
    }
  }

  &-year {
    position: absolute;
    top: ~'calc(50% - 0.5em)';
    left: @calendar-picker-padding;

    &-active {
      color: @calendar-month-dropdown-year-active-color;
    }
  }

  &-list {
    display: block;
    .clearfix;
  }

  &-cell {
    display: inline-block;
    float: left;
    width: ~'calc((100% - @{calendar-table-cell-content-today-border-width} * 12 ) / 6)';
    margin: 1px;
    text-align: center;
    vertical-align: middle;
  }

  &-cell-content {
    .picker-calendar-cell-content;
  }

  &-cell:not(&-cell-active).disabled &-cell-content {
    color: @B400;
    background: none;
    text-decoration: line-through;
    cursor: not-allowed;
  }

  &-cell-active.disabled &-cell-content {
    opacity: 0.3;
    cursor: not-allowed;
  }

  &-cell-active &-cell-content {
    .picker-calendar-cell-content-selected;
  }
}

// Calendar time dropdown
.@{clpns}-time-dropdown {
  display: none;
  position: absolute;
  top: @calendar-dropdown-top;
  padding-left: @calendar-picker-padding;
  padding-right: @calendar-picker-padding;
  width: 100%;
  background-color: @B000;
  overflow: hidden;
  z-index: @zindex-date-range-picker-table-cell-content;

  .@{clpns}-show-time-dropdown & {
    display: block;
  }

  .@{clpns}-show-time-dropdown &-content {
    animation: 0.3s linear slideDown;
  }

  &-row {
    display: table;
    width: 100%;
  }

  &-column {
    display: table-cell;
    width: 1%;

    > ul,
    > ul > li {
      list-style: none;
      margin: 0;
      padding: 0;
    }

    > ul {
      height: 230px;
      overflow-y: auto;
      padding-bottom: 200px;
    }
  }

  &-column-title {
    width: 100%;
    background-color: @calendar-time-dropdown-column-title-bg;
    color: @calendar-time-dropdown-column-title-font-color;
    text-align: center;
    font-size: @font-size-small;
    line-height: @line-height-small;
    padding-top: 2px;
    padding-bottom: 2px;
  }

  &-cell {
    font-size: @font-size-base;
    line-height: @line-height-computed;
    padding: 5px;
    display: block;
    color: @B800;
    text-align: center;
    cursor: pointer;
    transition: background-color 0.3s linear;

    &-active& {
      &,
      &:hover {
        background-color: @calendar-time-dropdown-column-cell-active-bg;
        color: @calendar-time-dropdown-column-cell-active-color;
      }
    }

    &,
    &:hover,
    &:focus {
      text-decoration: none;
    }

    &:hover {
      color: @calendar-time-dropdown-column-cell-default-color;
      background-color: @calendar-time-dropdown-column-cell-hover-bg;
    }

    &-disabled {
      &,
      &:hover,
      &:focus {
        color: @calendar-table-cell-content-disabled-color;
        background: none;
        cursor: not-allowed;
        text-decoration: line-through;
      }
    }

    &-active&-disabled& {
      opacity: 0.3;
      cursor: not-allowed;
    }
  }
}

// Toolbar
.@{ns}picker-toolbar {
  .clearfix;

  padding: @calendar-picker-padding;
  border-top: 1px solid @B200;

  &-ranges {
    display: inline-block;
    margin-left: -@padding-small-horizontal;
    margin-top: 5px;
  }

  &-right {
    float: right;
  }

  &-option {
    .btn(base);
    .btn-sm(base);
    .btn-link-variant(@calendar-option-color);

    padding-top: 0;
    padding-bottom: 0;

    &:not(:last-child) {
      position: relative;

      &::before {
        content: '';
        width: 1px;
        height: 20px;
        background-color: @B200;
        position: absolute;
        top: 0;
        right: 0;
      }
    }

    &-disabled {
      opacity: 0.3;
      cursor: not-allowed;

      .reset-link-text-decoration();
    }
  }

  &-right-btn-ok {
    .btn(base);
    .btn-sm(base);
    .button-primary-variant(@calendar-right-btn-ok-color; @calendar-right-btn-ok-bg);
  }

  &-right-btn-ok&-btn-disabled {
    opacity: 0.3;
    cursor: not-allowed;

    &,
    &:hover,
    &:hover:active {
      background-color: @calendar-right-btn-ok-bg;
    }
  }
}

// In picker menu
.@{ns}picker-menu .@{clpns} {
  width: @calendar-header-width;
  // To make sure <Calendar/> horizontal align at center when toolbar  width is so long.
  display: block;
  margin: 0 auto;

  .@{clpns}-month-dropdown-cell-content,
  .@{clpns}-table-cell-content {
    width: @calendar-in-menu-content-side-length;
    height: @calendar-in-menu-content-side-length;
  }

  .@{clpns}-table-header-row .@{clpns}-table-cell-content {
    height: 24px;
    padding-top: 0;
  }

  .@{clpns}-table-cell-content {
    padding-left: 0;
    padding-right: 0;
    display: inline-block;
  }

  .@{clpns}-month-dropdown-scroll {
    height: 227px;
  }

  .@{clpns}-time-dropdown-column > ul {
    height: 214px;
    padding-bottom: 184px;
  }
}

// Picker date
.@{ns}@{date-picker-prefix} {
  .@{ns}picker-toggle-caret::before {
    content: @calendar-default-caret-content !important;
    // Adjust the line-height to make sure icon vertical align middle.
    line-height: 17px;
  }

  &-only-time {
    .@{ns}picker-toggle-caret::before {
      content: @calendar-only-time-caret-content;
    }
  }

  &-inline {
    height: 299px;

    .@{clpns} {
      height: 286px;
    }
  }
}

// Show month dropdown
.@{clpns}-show-month-dropdown {
  .@{clpns}-header-month-toolbar {
    padding-left: 24px;
    padding-right: 24px;
  }

  .@{clpns}-header-backward,
  .@{clpns}-header-forward {
    display: none;
  }

  .@{clpns}-header-title-date {
    .picker-calendar-title-show;

    &.@{clpns}-header-error {
      color: @error-color;

      &:hover:active {
        color: @B000;
      }
    }
  }
}

// Show time dropdown
.@{clpns}-show-time-dropdown {
  .@{clpns}-header-title-time {
    .picker-calendar-title-show;

    &.@{clpns}-header-error {
      color: @error-color;

      &:hover:active {
        color: @B000;
      }
    }
  }
}

// Calendar group
.@{clpns}-table-cell-selected,
.@{clpns}-table-cell-in-range {
  position: relative;

  &::before {
    content: '';
    display: block;
    width: 100%;
    margin-top: 3px;
    height: 24px;
    position: absolute;
    z-index: @zindex-date-range-picker-table-cell-content - 1;
  }

  .@{clpns}-table-cell-content {
    z-index: @zindex-date-range-picker-table-cell-content;
    position: relative;
  }
}

.@{clpns}-table-cell-in-range::before {
  background-color: @H050;
}

// Reset outline for scroll list.
.@{clpns}-month-dropdown-scroll div:focus {
  outline: none;
}
